package com.lzh.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;

/**
 * @author zhehen.lu
 * @date 2025/8/3 14:14
 */
public class EasyExcelIntegerPercentConverter implements Converter<Integer> {
    public EasyExcelIntegerPercentConverter() {
    }

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        return (Integer) Converter.super.convertToJavaData(context);
    }

    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        return new WriteCellData(context.getValue() + "%");
    }
}
